/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-11-18 22:45:44
 * @LastEditors: 胡涛
 * @LastEditTime: 2023-11-18 23:17:44
 */
import api from "@/api";
import { ListResultDto, PagedListResultDto } from "../types";
import { GetHttpApiConfigInputDto, HttpApiConfigDto,ExportExcelInputDto } from "./types";

export default {
  /**
   * 获取单条记录
   * @param id
   * @param data
   * @returns
   */
  get(id: string): Promise<HttpApiConfigDto> {
    return api.get("/api/Platform/HttpApiConfig/" + id);
  },
  /**
   * 获取配置数据
   * @param code
   * @returns
   */
  getForCode(code: string): Promise<HttpApiConfigDto> {
    return api.get("/api/Platform/HttpApiConfig/config/" + code);
  },
  /**
   * 查询数据
   * @param code
   * @param input
   * @returns
   */
  query(code: string, input?: Record<string, any>): Promise<any> {
    return api.get("/api/Platform/HttpApiConfig/query/" + code, input);
  },
  /**
   * 执行请求
   * @param code
   * @param input
   * @returns
   */
  post(code: string, input?: Record<string, any>): Promise<any> {
    return api.post("/api/Platform/HttpApiConfig/query/" + code, input);
  },
  /**
   * 调用导出接口
   * @param code
   * @param input
   * @returns
   */
  export(code: string, input?: ExportExcelInputDto): Promise<any> {
    return api.post(
      "/api/Platform/HttpApiConfig/query/" + code + "/export",
      input
    );
  },

  /**
   * 获取列表
   * @param id
   * @param data
   * @returns
   */
  getList(
    data: Partial<GetHttpApiConfigInputDto>
  ): Promise<PagedListResultDto<HttpApiConfigDto>> {
    return api.get("/api/Platform/HttpApiConfig", data);
  },
  /**
   * 获取列表（不分页）
   * @param id
   * @param data
   * @returns
   */
  getAllList(
    data: Partial<GetHttpApiConfigInputDto>
  ): Promise<ListResultDto<HttpApiConfigDto>> {
    return api.get("/api/Platform/HttpApiConfig/all", data);
  },
  /**
   * 获取我的配置列表
   * @param data
   * @returns
   */
  getOwnsList(
    data: Partial<{ onlyEnabled: boolean }>
  ): Promise<ListResultDto<HttpApiConfigDto>> {
    return api.get("/api/Platform/HttpApiConfig/owns/list", data);
  },
  /**
   * 添加
   * @param id
   * @param data
   * @returns
   */
  create(data: Partial<HttpApiConfigDto>): Promise<HttpApiConfigDto> {
    return api.post("/api/Platform/HttpApiConfig", data);
  },
  /**
   * 修改
   * @param id
   * @param data
   * @returns
   */
  update(
    id: string,
    data: Partial<HttpApiConfigDto>
  ): Promise<HttpApiConfigDto> {
    return api.put("/api/Platform/HttpApiConfig/" + id, data);
  },
  /**
   * 删除
   * @param id
   * @returns
   */
  delete(id: string): Promise<HttpApiConfigDto> {
    return api.delete("/api/Platform/HttpApiConfig/" + id);
  },
};
